using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum CommandType
{
    Null,
    SetName,
    NewPage,
    Section,
    SetMiddle,
}

public class Command
{
    static public Dictionary<string, CommandType> strToCode = new Dictionary<string, CommandType>()
    {
        ["SetName"] = CommandType.SetName,
        ["NewPage"] = CommandType.NewPage,
        ["Section"] = CommandType.Section,
        ["SetMiddle"] = CommandType.SetMiddle,
    };

    public CommandType commandType;
    public List<string> parameters;

    public Command(CommandType type=CommandType.Null,List<string> parameters=null)
    {
        this.commandType = type;
        this.parameters = parameters;
    }

    public static Command Parse(string str)
    {
        var strs = str.Split('(', ',', ')');
        CommandType type;
        if (strToCode.TryGetValue(strs[0], out type))
        {
            var pars = new List<string>();
            for (int i = 1; i < strs.Length; i++)
            {
                pars.Add(strs[i]);
            }
            return new Command(type, pars);
        }
        return null;
    }
}
